/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.solitaire.web.controller.api;

import com.medusa.gruul.common.core.annotation.EscapeLogin;
import com.medusa.gruul.common.core.util.PageUtils;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.solitaire.api.entity.InformationTopic;
import com.medusa.gruul.solitaire.api.model.dto.api.ApiInformationMessageDto;
import com.medusa.gruul.solitaire.api.model.param.api.ApiInformationInfoParam;
import com.medusa.gruul.solitaire.api.model.param.api.ApiInformationMessageParam;
import com.medusa.gruul.solitaire.api.model.vo.api.ApiInformationInfoVo;
import com.medusa.gruul.solitaire.api.model.vo.api.ApiInformationMessageVo;
import com.medusa.gruul.solitaire.api.model.vo.api.ApiInformationSetVo;
import com.medusa.gruul.solitaire.service.api.IApiInformationInfoService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 小程序资讯信息信息 前端控制器
 * </p>
 *
 * @author lcysike
 * @since 2021-05-26
 */
@RestController
@RequestMapping("/api/information/info")
public class ApiInformationInfoController {

    @Autowired
    private IApiInformationInfoService iApiInformationInfoService;

    /**
     * 获取资讯设置信息
     */
    @GetMapping("/get")
    @ApiOperation(value = "获取资讯设置信息")
    public Result<ApiInformationSetVo> getInformationSet() {
        ApiInformationSetVo apiInformationSetVo = iApiInformationInfoService.getInformationSet();
        return Result.ok(apiInformationSetVo);
    }

    /**
     * 获取资讯专题信息
     */
    @GetMapping("/topic/list")
    @ApiOperation(value = "获取资讯专题信息")
    public Result<List<InformationTopic>> topicList() {
        return Result.ok(iApiInformationInfoService.topicList());
    }

    /**
     * 获取资讯列表信息
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取资讯列表信息")
    public Result<PageUtils<ApiInformationInfoVo>> list(ApiInformationInfoParam apiInformationInfoParam) {
        PageUtils<ApiInformationInfoVo> pageUtils = new PageUtils(iApiInformationInfoService.list(apiInformationInfoParam));
        return Result.ok(pageUtils);
    }

    /**
     * 获取单条资讯信息
     */
    @GetMapping("/get/{id}")
    @ApiOperation(value = "获取单条资讯信息")
    public Result<ApiInformationInfoVo> get(@ApiParam(value = "资讯信息id", required = true) @PathVariable(name = "id") Long id) {
        ApiInformationInfoVo apiInformationInfoVo = iApiInformationInfoService.get(id);
        return Result.ok(apiInformationInfoVo);
    }

    /**
     * 资讯阅读量增加
     */
    @PutMapping("/set/read/{id}")
    @ApiOperation(value = "资讯阅读量增加")
    public Result setRead(@ApiParam(value = "资讯信息id", required = true) @PathVariable(name = "id") Long id) {
        iApiInformationInfoService.setRead(id);
        return Result.ok();
    }

    /**
     * 获取资讯留言列表信息
     */
    @GetMapping("/get/message/list")
    @ApiOperation(value = "获取资讯留言列表信息")
    public Result<PageUtils<ApiInformationMessageVo>> getMessageList(ApiInformationMessageParam apiInformationMessageParam) {
        PageUtils<ApiInformationMessageVo> pageUtils = new PageUtils(iApiInformationInfoService.getMessageList(apiInformationMessageParam));
        return Result.ok(pageUtils);
    }

    /**
     * 资讯信息留言
     */
    @PostMapping("/leave")
    @ApiOperation(value = "资讯留言)")
    public Result leave(@RequestBody @Validated ApiInformationMessageDto apiInformationMessageDto) {
        iApiInformationInfoService.leave(apiInformationMessageDto);
        return Result.ok();
    }

    /**
     * 资讯信息点赞
     */
    @PostMapping("/like/{type}/{infoId}")
    @ApiOperation(value = "资讯信息点赞)")
    public Result like(@ApiParam(value = "操作类型 0-点赞 1-取消点赞", required = true) @PathVariable(name = "type") Integer type,
                       @ApiParam(value = "资讯id", required = true) @PathVariable(name = "infoId") Long infoId) {
        iApiInformationInfoService.like(type, infoId);
        return Result.ok();
    }

    /**
     * 资讯留言点赞
     */
    @PostMapping("/message/like/{type}/{messageId}")
    @ApiOperation(value = "资讯留言点赞)")
    public Result messageLike(@ApiParam(value = "操作类型 0-点赞 1-取消点赞", required = true) @PathVariable(name = "type") Integer type,
                              @ApiParam(value = "资讯留言id", required = true) @PathVariable(name = "messageId") Long messageId) {
        iApiInformationInfoService.messageLike(type, messageId);
        return Result.ok();
    }

    /**
     * 资讯留言删除
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "资讯留言删除")
    public Result deleteActivity(@ApiParam(value = "资讯留言id", required = true) @PathVariable(name = "id") Long id) {
        iApiInformationInfoService.delete(id);
        return Result.ok();
    }
}
